//配置路由相关信息

import Vue from 'vue'
import VueRouter from 'vue-router'

// import home from '../components/home'
// import about from '../components/About'
// import user from '../components/user'

//路由懒加载
const home = () => import('../components/home')
const about = () => import('../components/About')
const user = () => import('../components/user')
const message = () => import('../components/home/message')
const news = () => import('../components/home/news')
const profile = () => import('../components/profile')


//1.vue.use(插件)，安装插件

Vue.use(VueRouter)

//2.创建vueRouter对象

const routes = [
  {
    path: '/home',
    component: home,
    meta: {
      title: "首页"
    },
    children: [
      
      {
        path: 'message',
        component: message
      },
      {
        path: 'news',
        component: news
      }
    ]
  },
  {
    path: '/about',
    component: about,
    meta: {
      title: "关于"
    }
  },
  {
    path: '/profile',
    component: profile,
    meta: {
      title: "档案"
    }
  },
  {
    path: '/user/:userId',
    component: user,
    meta: {
      title: "用户"
    }
  }
]

const router = new VueRouter({
  //配置路由和组件之间的映射关系
  routes,
  mode: 'history',
  linkActiveClass: 'active'
})

router.beforeEach((to, from, next) => {
  document.title = to.matched[0].meta.title
  next()
})

export default router